package com.hnchances.studentscoresystem.service.impl;

import com.hnchances.studentscoresystem.entity.Exam;
import com.hnchances.studentscoresystem.mapper.ExamMapper;
import com.hnchances.studentscoresystem.service.ExamService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 考试管理 Service 实现类
 */
@Service
public class ExamServiceImpl extends BaseServiceImpl<Exam, Integer, ExamMapper> implements ExamService {

    @Override
    public boolean insert(Exam exam) {
        // 补全默认值：状态默认为 0（正常）
        if (exam.getStatus() == null) {
            exam.setStatus(0);
        }
        return mapper.insert(exam) > 0;
    }

    @Override
    public Exam selectById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public List<Exam> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public boolean update(Exam exam) {
        return mapper.update(exam) > 0;
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteById(id) > 0;
    }

    @Override
    public Exam selectByExamName(String examName) {
        List<Exam> examList = mapper.selectByNameLike(examName);
        return examList.isEmpty() ? null : examList.get(0);
    }
}